package com.jinmdz.fmis.api.admin.controller;

import com.jinmdz.fmis.api.admin.model.rolerelation.BusinessSystemRoleIdData;
import com.jinmdz.fmis.api.admin.model.rolerelation.RoleUserRelationSaveData;
import com.jinmdz.fmis.api.admin.service.RoleRelationService;
import com.jinmdz.fmis.api.api.model.common.IdVersionData;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.dao.admin.model.rolerelation.RoleUserListItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * 角色、用户信息关联关系维护相关接口
 *
 * @author LiCongLu
 * @date 2020-03-19 10:29
 */
@Api(description = "角色、用户信息关联关系维护相关接口")
@RestController()
@RequestMapping("/admin/role-user-relation")
public class RoleUserRelationController extends BaseController {

    @Resource
    private RoleRelationService roleRelationService;

    /**
     * 根据角色id加载角色下包含的用户数据
     *
     * @param data 角色主键
     * @return
     * @author LiCongLu
     * @date 2020-03-18 17:25
     */
    @ApiOperation(value = "根据角色id加载角色下包含的用户数据", notes = "根据角色id加载角色下包含的用户数据，关联表【role_user_relation】，用户表【system_user】")
    @PostMapping("/load-role-user-with-role-id")
    public BaseResult<ArrayList<RoleUserListItem>> loadRoleUserWithRoleId(@RequestBody BusinessSystemRoleIdData data) {
        return resultHandler(data, userItem -> roleRelationService.loadRoleUserWithRoleId(data));
    }

    /**
     * 保存角色用户关联信息
     *
     * @param data 角色与用户关联信息
     * @return
     * @author LiCongLu
     * @date 2020-03-18 17:26
     */
    @ApiOperation(value = "保存角色用户关联信息", notes = "保存角色用户关联信息到表【role_user_relation】中")
    @PostMapping("/save-role-user-relation")
    public BaseResult saveRoleUserRelation(@RequestBody ArrayList<RoleUserRelationSaveData> data) {
        return resultHandler(data, userItem -> roleRelationService.saveRoleUserRelation(userItem, data));
    }

    /**
     * 删除角色与用户关联关系
     *
     * @param data 主键和数据版本号
     * @return
     * @author LiCongLu
     * @date 2020-03-19 10:37
     */
    @ApiOperation(value = "删除角色与用户关联关系", notes = "从表【role_user_relation】中删除按钮数据信息")
    @PostMapping("/delete-role-user-relation-with-id")
    public BaseResult deleteRoleUserRelationWithId(@RequestBody ArrayList<IdVersionData> data) {
        return resultHandler(data, userItem -> roleRelationService.deleteRoleUserRelationWithId(userItem, data));
    }
}
